#pragma once

//#include "WaitBoxHelper.h"
struct FFTOutput{
	int channel;
	int eid;
	std::complex<double> *out;
	int b;
	int e;

	double median;
	double average;
	double max;
	int max_index;
	double *abs;

	FFTOutput(int ch,int id,std::complex<double> * o,int beg,int end):eid(id),
		out(o),channel(ch),b(beg),e(end){}
};

struct FFT_CalcParams{
	std::vector<int> channels_eid ;
	unsigned int startpt;
	unsigned int endpt;
};

class FFTCalculator
{
	static FFTCalculator *instance;
	FFTCalculator(void);
	bool isOutputReady;
	std::vector<FFTOutput> out;
	const DataStore *source;
	CWaitBoxDlg wbd;
	void DoCalc(const FFT_CalcParams p);//calc the fft of the n-th ch.
	void KillAOutput(FFTOutput &o);
	friend void FFT_Working_Thread( LPVOID );
public:
	~FFTCalculator(void);
	static FFTCalculator *GetInstance(){
		if(!instance)
			instance = new FFTCalculator();
		return instance;
	}

	static void DestoryInstance(){
		if(instance)
			delete instance;
	}

	int EID2Index(int eid) const ;
	int Index2EID(UINT index) const {if(index>=out.size()) return -1; return out[index].eid;};
	const std::vector<FFTOutput> &GetOutputs() const{return out;}
	const DataStore* GetSource() const {return source;}
	size_t GetOutputCount() const { return out.size();}
	bool StartCalc(const FFT_CalcParams p);
	bool isReady() const{ return isOutputReady;};
	//void SetSource(const DataStore *s){source = s;}
	bool Export2File (LPCTSTR filename, int eid)const;
	void reset(void);
};
